package kotlinquanweizhinan.chapt4函数.自定义函数
fun main(){
    val name = "Madrigal"
    val healthPoints = 80
    val isBlessed = true //是否走运
    val isImmortal = false //记录玩家是否永生

    val auraColor = auraColor(isBlessed, healthPoints, isImmortal)

    //使用string横版
    println("(Aura:$auraColor) "+ "(Blessed:${if(isBlessed) "YES" else "NO"})")
    printPlayerStatus(healthPoints, isBlessed, name)

   // castFireball()
    castFireball(5)
}

private fun printPlayerStatus(healthPoints: Int, isBlessed: Boolean, name: String) {
    //使用when表达重构healthStatus求值
    val healthStatus = formatHealthStatus(healthPoints, isBlessed)

    //Player status
    println(name + " " + healthStatus)
}

private fun auraColor(isBlessed: Boolean, healthPoints: Int, isImmortal: Boolean): String {
    val auraVisible = isBlessed && healthPoints > 50 || isImmortal //在变量定义时使用逻辑运行符

//    if(auraVisible){
//        println("GREEN")
//    }else{
//        println("NONE")
//    }

    //使用条件表达式优化光环判断代码
    val auraColor = if (auraVisible) "GREEN" else "NONE"
    return auraColor
}

//单表达式函数
private fun formatHealthStatus(healthPoints: Int, isBlessed: Boolean)=
    when (healthPoints) {
        100 -> "is in excellent conditioin!"
        in 90..99 -> "has a few scrateches."
        in 75..89 -> if (isBlessed) {
            "has some minor woonds but is healing quite quickly!"
        } else {
            " has some minor wounds."
        }
        in 15..74 -> " looks pretty hurt."
        else -> "is in awful condition!"
    }



//单表达式函数
private fun castFireball(numFireballs:Int=2)=
    println("A glass of Fireball sprints int existence.(x$numFireballs) ")
